package com.fuqi.android.zhongcai.business.shuig.view.activity;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.ApiUrl;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.business.shuig.view.widget.BGASortableNinePhotoLayoutView;
import com.fuqi.android.zhongcai.business.shuig.view.widget.CJRow.ARResponse;
import com.fuqi.framework.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity;

public class CompleteShowActivity extends BaseActivity implements BGASortableNinePhotoLayoutView.Delegate{
    @Bind(R.id.iv_azwc_sbhb)
    ImageView mIvSbhb;
    @Bind(R.id.iv_azwc_wxts)
    ImageView mIvWxts;
    @Bind(R.id.iv_azwc_ylqd)
    ImageView mIvYlqd;
    @Bind(R.id.iv_azwc_fwk)
    ImageView mIvFwk;
    @Bind(R.id.iv_azwc_zbk)
    ImageView mIvZbk;
    @Bind(R.id.iv_azwc_bytp)
    ImageView mIvBytp;

    private BGASortableNinePhotoLayoutView ninePhotoLayout;
    private String sPathSbhb,sPathWxts,sPathYlqd,sPathFwk,sPathZbk,sPathBytp;
    private ArrayList<String> selectedPhotos = new ArrayList<>();
    private ArrayList<String> netPhotos = new ArrayList<>();
    ARResponse response;

    @OnClick({R.id.iv_azwc_sbhb,R.id.iv_azwc_wxts,R.id.iv_azwc_ylqd,R.id.iv_azwc_fwk
            ,R.id.iv_azwc_zbk,R.id.iv_azwc_bytp})
    public void onClick(View v){
        switch (v.getId()) {
            case R.id.iv_azwc_sbhb:
                choicePhotoWrapper(netPhotos,0);
                break;
            case R.id.iv_azwc_wxts:
                choicePhotoWrapper(netPhotos,1);
                break;
            case R.id.iv_azwc_ylqd:
                choicePhotoWrapper(netPhotos,2);
                break;
            case R.id.iv_azwc_fwk:
                choicePhotoWrapper(netPhotos,3);
                break;
            case R.id.iv_azwc_zbk:
                choicePhotoWrapper(netPhotos,4);
                break;
            case R.id.iv_azwc_bytp:
                choicePhotoWrapper(netPhotos,5);
                break;
        }
    }

    private void choicePhotoWrapper(List<String> models,int position) {
        startActivity(BGAPhotoPreviewActivity.newIntent(this, null, (ArrayList<String>) models,position));
    }

    private void showPic(String path,ImageView iv){
        Glide.with(getApplicationContext())
                .load(path)
                .placeholder(R.mipmap.azwc_add)
                .crossFade()
                .centerCrop()
                .into(iv);
    }

    @Override
    public void initView() {
        titleBar.setTitle("查看图片");
        ninePhotoLayout = (BGASortableNinePhotoLayoutView) findViewById(R.id.activity_discover_invest_publish_nine_photo);
        ninePhotoLayout.init(CompleteShowActivity.this);
        ninePhotoLayout.setDelegate(CompleteShowActivity.this);
//        ninePhotoLayout.set

    }


    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        response = new ARResponse(getIntent().getStringExtra("response"));
        sPathSbhb = ApiUrl.getDefaultHost()+response.getValue("PIC_THREE_PROTECT");
        sPathWxts = ApiUrl.getDefaultHost()+response.getValue("PIC_ATTENTION");
        sPathYlqd = ApiUrl.getDefaultHost()+response.getValue("PIC_DETAIL_LIST");
        sPathFwk = ApiUrl.getDefaultHost()+response.getValue("PIC_SERVICE_CARD");
        sPathZbk = ApiUrl.getDefaultHost()+response.getValue("PIC_WARRANTY_CARD");
        sPathBytp = ApiUrl.getDefaultHost()+response.getValue("PIC_PRESS_PROTECT");

        String path = response.getValue("PIC_FINISH");
        netPhotos.add(sPathSbhb);
        netPhotos.add(sPathWxts);
        netPhotos.add(sPathYlqd);
        netPhotos.add(sPathFwk);
        netPhotos.add(sPathZbk);
        netPhotos.add(sPathBytp);
        selectedPhotos = StringUtil.getListWithPath(path,",");
        netPhotos.addAll(selectedPhotos);

        showPic(sPathSbhb,mIvSbhb);
        showPic(sPathWxts,mIvWxts);
        showPic(sPathYlqd,mIvYlqd);
        showPic(sPathFwk,mIvFwk);
        showPic(sPathZbk,mIvZbk);
        showPic(sPathBytp,mIvBytp);
        ninePhotoLayout.setData(selectedPhotos);
    }

    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_complete_ck;
    }


    @Override
    public void onClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        startActivity(BGAPhotoPreviewActivity.newIntent(this, null, (ArrayList<String>) models, position));
    }

    @Override
    public boolean onLongClickNinePhotoItem(BGASortableNinePhotoLayoutView ninePhotoLayout, View view, int position, String model, List<String> models) {
        return false;
    }

}
